package cn.hfatec.shms.web.hj.hjTotal.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.hj.hjTotal.model.HjTotal;
import cn.hfatec.shms.web.hj.hjTotal.dao.HjTotalDao;
import cn.hfatec.shms.web.hj.hjTotal.model.HjTotalParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("HjTotalService")
public class HjTotalService {

    public static final String BEAN_ID = "HjTotalService";

    //注入Dao层
    @Resource(name = "HjTotalDao")
    private HjTotalDao hjTotalDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param hjTotalParams
     * @param page
     *
     */
    @Transactional
    public Table queryHjTotalTable(HjTotalParams hjTotalParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", hjTotalParams);
        return baseDao.queryTableByPage("queryHjTotal", params, page);
    }

    /**
     *
     * 插入数据
     * @param hjTotal
     *
     */
    @Transactional
    public void saveHjTotal(HjTotal hjTotal) {
        if(hjTotal.getId() != null) {
            HjTotal result = getHjTotal(hjTotal.getId());
            if(result != null) {
                hjTotalDao.update(hjTotal);
            } else {
                hjTotalDao.insert(hjTotal);
            }
        } else {
            hjTotalDao.insert(hjTotal);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteHjTotal(Integer id) {

        hjTotalDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param hjTotalList
     *
     */
    @Transactional
    public void deleteHjTotalBatch(List<String> hjTotalList) {
        for(String id : hjTotalList) {
            deleteHjTotal(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public HjTotal getHjTotal(Integer id) {

        return hjTotalDao.getHjTotalById(id);
    }
}